var express=require("express");
var router=require('./routers');
var template=require('express-art-template');
var bodyParser = require('body-parser')
var app=express();
    app.all('*', function(req, res, next) {
    //设为指定的域
    res.header('Access-Control-Allow-Origin', "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    res.header('Access-Control-Allow-Credentials', true);
    res.header("X-Powered-By", ' 3.2.1');
    next();
});
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use('/node_modules/',express.static('./node_modules/'))
app.use('/public/',express.static('./public/'))
app.engine('html',template)
// app.all('*', function(req, res, next) {
//     res.header("Access-Control-Allow-Origin", "*");
//     res.header("Access-Control-Allow-Headers", "X-Requested-With");
//     res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
//     res.header("X-Powered-By",' 3.2.1')
//     res.header("Content-Type", "application/json;charset=utf-8");
//     next();
// });
let session = require("express-session");

var prot=3000;
app.use(session({
    secret: '123', //密钥
    resave: false,
    saveUninitialized: true,
    name: "doudou", //给本地cookie设置一个值;
    cookie: {
        maxAge: 100000000 // 设置最大存活时间
    },
    //在每次请求时强行设置 cookie，这将重置 cookie 过期时间（默认：false）
    rolling: true
}))
app.use('/',router)
app.listen(prot,function(){
    console.log(`服务器启动成功，检测端口号是3000!`)
})
